<div class="row">
  <div class="col-xs-12">
    <div class="box box-primary">
      <div class="box-header">
        <h3 class="box-title">Tambah Surat Kontrol</h3>
      </div><!-- /.box-header -->
      <?php echo form_open('surat_kontrol/save', array('role' => 'form', 'id' => 'form', 'enctype' => 'multipart/form-data'));?>
      <div class="box-body">	
      	<div class="row">	
      		<div class="col-sm-6">		        
            <!-- text input -->
            <div class="form-group">
              <label>No. Jaminan</label>
              <span class="pull-right">
                <a href="#" onClick="return kd_jaminan()">
                  <i class="glyphicon glyphicon-check" style="color: #3C8DBC"></i>
                </a>
              </span>
             	<input class="form-control input-sm" name="kd_jaminan" id="kd_jaminan" type="text" placeholder="No. Jaminan">
            </div>
            <div class="form-group">
              <label>Nama</label>
             	<input class="form-control input-sm" name="nama" id="nama" type="text" placeholder="Nama Peserta" disabled>
            </div>
            <div class="form-group">
              <label>Alamat</label>
             	<input class="form-control input-sm" name="alamat" id="alamat" type="text" placeholder="Alamat" disabled>
            </div>
            <div class="form-group">
              <label>Tempat, Tanggal Lahir</label>
             	<input class="form-control input-sm" name="ttl" id="ttl" type="text" placeholder="Tempat, Tanggal Lahir" disabled>
            </div>
            <div class="form-group">
              <label>PPK</label>
              <select class="form-control input-sm" name="ppk" id="ppk" disabled>
                <option value="0"> - - Pilih PPK - - </option>
                <?php
                  foreach ($ppk as $value) {
                    echo "<option value=".$value['kd_ppk'].">".$value['ppk']."</option>";
                  }
                ?>
              </select>
            </div>
            <div class="form-group">
              <label>Tanggal Kontrol</label>
              <input class="form-control input-sm" name="tanggal" id="tanggal" type="text" value="<?php echo date('d/m/Y'); ?>" readonly style="background: #fff">
            </div>
        </div>
      </div>		                   
      <div class="box-footer">
        <button type="submit" class="btn btn-sm btn-primary btn-flat"><i class="fa fa-floppy-o"></i> Simpan</button>
      </div>
			<?php echo form_close();?>
    </div><!-- /.box -->                            
  </div>
</div>

<script>
$("#form").validate({
	rules: {
    kd_peserta: {
      required: true
    },
		ppk: {
			required: true
		},
    jenis_kunjungan: {
      required: true
    },
	}
});
</script>

<script type="text/javascript">
  function kd_jaminan(){
    var send_data = {
        kd_jaminan: $("#kd_jaminan").val(),
        <?php echo $this->security->get_csrf_token_name(); ?>: "<?php echo $this->security->get_csrf_hash(); ?>",
      };

    $.ajax({
      type: "POST",
      url: "<?php echo base_url() ?>surat_kontrol/get_peserta",
      data: send_data,
      cache: false,
      dataType: 'json',
      success: function(msg){
        $("#nama").val(msg.nama);
        $("#alamat").val(msg.alamat);
        $("#ttl").val(msg.ttl);
        $("#ppk").val(msg.ppk);
      }
    });
  }
</script>
  
<script type="text/javascript">
  function pilih(id){
    alert(id);
  }
</script>

<script type="text/javascript">
  function hapusData(obj){  
    if (confirm('Apakah data akan dihapus ?')) {
      obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
    }
  }

  function add_data(){
    var tampil_tombol_aksi = '<a href="javascript:void(null)" class="btn btn-xs btn-danger btn-flat pull-right" title="Hapus" onclick="hapusData(this)"><i class="fa fa-trash-o"></i></a>';
    var tr = document.createElement('tr');
    var td_diagnosis = document.createElement('td');   
    var td_aksi = document.createElement('td');     
    var tbodi = document.getElementById("tbl-diagnosa");

    td_aksi.className = 'links';
    td_diagnosis.innerHTML = "<select class='form-control diagnosa' name='diagnosa[]'><option> - - Pilih Diagnosa - - </option><?php foreach ($diagnosa as $value) { echo "<option value='$value[kd_diagnosa]'>$value[diagnosa]</option>";}?></select>";
    td_aksi.innerHTML = tampil_tombol_aksi;
    tr.appendChild(td_diagnosis);
    tr.appendChild(td_aksi);
    tbodi.appendChild(tr);
    $(".diagnosa").select2();
  }
</script>

<script type="text/javascript">
  function hapusLampiran(obj){  
    if (confirm('Apakah data akan dihapus ?')) {
      obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
    }
  }

  function add_lampiran(){
    var aksi_lampiran = '<a href="javascript:void(null)" class="btn btn-xs btn-danger btn-flat pull-right" title="Hapus" onclick="hapusLampiran(this)"><i class="fa fa-trash-o"></i></a>';
    var tr = document.createElement('tr');
    var td_lampiran = document.createElement('td');   
    var td_aksi = document.createElement('td');     
    var tbodi = document.getElementById("tbl-lampiran");

    td_aksi.className = 'links';
    td_lampiran.innerHTML = "<input type='file' name='lampiran[]'>";
    td_aksi.innerHTML = aksi_lampiran;
    tr.appendChild(td_lampiran);
    tr.appendChild(td_aksi);
    tbodi.appendChild(tr);
  }
</script>

<script type="text/javascript">
  $(document).ready(function() {
    $(".diagnosa").select2();
  });
</script>

<script type="text/javascript">
  $(document).ready(function(){
    $('#tanggal').datepicker({
      dateFormat: "dd/mm/yy",
      changeMonth: true,
      changeYear: true
    });
  });
</script>        